import socket
import json
import struct
sk=socket.socket()
sk.bind(('127.0.0.1',9001))

sk.listen()
conn,addr=sk.accept()
msg_len=conn.recv(4)
dic_len=struct.unpack('i',msg_len)[0]
msg=conn.recv(dic_len).decode('utf-8')
msg=json.loads(msg)

#接收小文件
# with open(msg['filename'],mode='wb') as f:
#     content=conn.recv(msg['filesize'])
#     print(content,len(content))
#     f.write(content)

#接收大文件
with open(msg['filename'],mode='wb') as f:
    while msg['filesize'] >0:
        content=conn.recv(1024)
        msg['filesize']-=len(content)
        f.write(content)

conn.close()
sk.close()


















